import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ts_app_dart/store/index.dart';
import 'package:ts_app_dart/utils/index.dart';

class ElectronPage extends StatefulWidget {
  final globalController = Get.put(GlobalStateController());

  ElectronPage({Key key}) : super(key: key);

  @override
  _ElectronPageState createState() => _ElectronPageState();
}

class _ElectronPageState extends State<ElectronPage> {
  String applicationId;

  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 3, // 导航项的数量
      child: Scaffold(
        appBar: AppBar(
          // leading: Padding(
          //   padding: EdgeInsets.all(12),
          //   child: InkWell(
          //     onTap: () {},
          //     child: ClipRRect(
          //       borderRadius: BorderRadius.circular(30),
          //       child: Image(
          //         image: AssetImage('images/avatar.png'),
          //       ),
          //     ),
          //   ),
          // ),
          title: TabBar(
            tabs: <Widget>[
              Tab(text: '首页'),
              Tab(text: '动态'),
              Tab(text: '我的'),
            ],
          ),
          actions: [
            IconButton(
              onPressed: () {
                widget.globalController.changeBottomBarIndex(1);
                Get.offAllNamed('/', arguments: {'barIndex': 1});
              },
              padding: EdgeInsets.all(0.0),
              icon: Icon(
                Icons.explore_outlined,
                size: 24.0,
              ),
            )
          ],
          // title: Text('顶部导航栏'),
          // bottom: TabBar(
          //   tabs: <Widget>[
          //     Tab(text: '首页'),
          //     Tab(text: '动态'),
          //     Tab(text: '我的'),
          //   ],
          // ),
        ),
        body: TabBarView(
          children: <Widget>[
            Center(child: Text('首页')),
            Container(
              child: Column(
                children: [
                  Center(
                    child: IconButton(
                      iconSize: 48,
                      icon: Icon(
                        Icons.add_box_rounded,
                      ),
                      onPressed: () {
                        CommonUtils.loadAppVersion().then((value) {
                          setState(() {
                            applicationId = value.data['applicationId'];
                          });
                        });
                      },
                    ),
                  ),
                  Padding(
                    padding: EdgeInsets.all(12.0),
                    child: Center(
                      child: Text(applicationId ?? 'applicationId'),
                    ),
                  ),
                  Card(
                    margin: const EdgeInsets.all(10),
                    child: Column(
                      children: [
                        Container(
                          height: 50,
                          padding: const EdgeInsets.only(left: 10, right: 10),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              const Text('Card Title',
                                  style: TextStyle(fontSize: 18)),
                              TextButton(
                                onPressed: () => print('more...'),
                                style: TextButton.styleFrom(
                                    minimumSize: Size.zero),
                                child: const Text('more'),
                              ),
                            ],
                          ),
                        ),
                        const Divider(height: 0),
                        Image.network(
                          'https://gw.alipayobjects.com/zos/rmsportal/JiqGstEfoWAOHiTxclqi.png',
                          width: double.infinity,
                          fit: BoxFit.cover,
                        ),
                        const Divider(height: 0),
                        ListTile(
                          leading: Container(
                            width: 40,
                            height: 40,
                            decoration: const BoxDecoration(
                              color: Colors.lightBlue,
                              borderRadius:
                                  BorderRadius.all(Radius.circular(20)),
                            ),
                            child: const Icon(Icons.face, color: Colors.white),
                          ),
                          title: const Text('Card Title'),
                          subtitle: const Text('This is the description ...'),
                        ),
                        const Divider(height: 0),
                        SizedBox(
                          height: 50,
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                            children: [
                              IconButton(
                                  onPressed: () => print('设置'),
                                  icon: const Icon(Icons.settings),
                                  color: Colors.grey),
                              const VerticalDivider(),
                              IconButton(
                                  onPressed: () => print('编辑'),
                                  icon: const Icon(Icons.edit),
                                  color: Colors.grey),
                              const VerticalDivider(),
                              IconButton(
                                  onPressed: () => print('更多'),
                                  icon: const Icon(Icons.more),
                                  color: Colors.grey),
                            ],
                          ),
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ),
            Center(child: Text('我的内容')),
          ],
        ),
      ),
    );
  }
}
